import { Component } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {

  title = 'aaa';
  credentials = {username:'lixinlei',password:'123456'};
  authenticated = false;
  order = {id:11111, productId:111111};
    
  constructor(private http : HttpClient) {
    
  }

  logout() {
    this.http.get('logout').subscribe((success) => {
      this.authenticated = false;
    }, (error) => {
      console.log("logout error");
      console.log(error);
    })
  }

  getOrder() {
    this.http.get('api/order/orders/1').subscribe(data => {
      console.log(data);
      this.order = (<any>data);
    }, (error) => {
      console.log("get order error");
      console.log(error);
    });
  }

  login() {
    this.http.post('login',this.credentials).subscribe((success) => {
      console.log(success);
      this.authenticated = true;
    }, (error) => {
      console.log("login error");
      console.log(error);
    })
  }

}
